﻿#include"FITKOCCModelMetalForming.h"
#include <gp_Ax2.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Wire.hxx>
#include <gp_Circ.hxx>
#include <GC_MakeArcOfCircle.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <BRepPrimAPI_MakeRevol.hxx>
namespace OCC
{

    FITKOCCModelUpDie::FITKOCCModelUpDie():OCCShapeAgent(this)
    {
        _shapeAgent=_occShapeAgent;
    }

    bool FITKOCCModelUpDie::update()
    {
        //异常处理
        try
        {
            double p1[3];
            p1[0]=_location[0];p1[1]=_location[1];p1[2]=_location[2];
            double p2[3];
            p2[0]=_location[0]+_length1;p2[1]=_location[1];p2[2]=_location[2];
            double p3[3];
            p3[0]=_location[0]+_length1+_radius;p3[1]=_location[1];p3[2]=_location[2]+_radius;
            double p4[3];
            p4[0]=_location[0]+_length1+2*_radius;p4[1]=_location[1];p4[2]=_location[2]+2*_radius;
            double p5[3];
            p5[0]=_location[0]+_length1+_length2+2*_radius;p5[1]=_location[1];p5[2]=_location[2]+2*_radius;
            double p6[3];
            p6[0]=_location[0]+_length1+_length2+2*_radius;p6[1]=_location[1];p6[2]=_location[2]+2*_radius+_length3;
            double p7[3];
            p7[0]=_location[0];p7[1]=_location[1];p7[2]=_location[2]+2*_radius+_length3;
            double o1[3];
            o1[0]=_location[0]+_length1;o1[1]=_location[1];o1[2]=_location[2]+_radius;
            double o2[3];
            o2[0]=_location[0]+_length1+2*_radius;o2[1]=_location[1];o2[2]=_location[2]+_radius;

            //先求解第一段圆弧中点坐标，在利用三点画圆弧（解直线和圆交点坐标）
            double y1 = o1[2] - (p2[2] + p3[2]) / 2;
            double x1 = o1[0] - (p2[0] + p3[0]) / 2;
            double m1 = y1 / x1;
            double n1 = -m1 * o1[0] + o1[2];
            double A1 = 1 + m1 * m1;
            double B1 = 2*m1*(n1-o1[2])-2*o1[0];
            double C1=o1[0]*o1[0]+(n1-o1[2])*(n1-o1[2])-_radius*_radius;
            double p23[3];
            double jie1 = (-B1 + sqrt(B1*B1-4*A1*C1))/(2*A1);
            double jie2 = (-B1 - sqrt(B1*B1-4*A1*C1))/(2*A1);
            if(jie1<=p3[0]&&jie1>=p2[0])
            {
                p23[0]=jie1;
            }
            else
            {
               p23[0]=jie2;
            }
            p23[1]=_location[1];p23[2]=m1*p23[0]+n1;

        //先求解第二段圆弧中点坐标，在利用三点画圆弧（解直线和圆交点坐标）
            double y2 = o2[2] - (p4[2] + p3[2]) / 2;
            double x2 = o2[0] - (p4[0] + p3[0]) / 2;
            double m2 = y2 / x2;
            double n2 = -m2 * o2[0] + o2[2];
            double A2 = 1 + m2 * m2;
            double B2 = 2*m2*(n2-o2[2])-2*o2[0];
            double C2=o2[0]*o2[0]+(n2-o2[2])*(n2-o2[2])-_radius*_radius;
            double p34[3];
            double jie3 = (-B2 + sqrt(B2*B2-4*A2*C2))/(2*A2);
            double jie4 = (-B2 - sqrt(B2*B2-4*A2*C2))/(2*A2);
            if(jie3<=p4[0]&&jie3>=p3[0])
            {
                p34[0]=jie3;
            }
            else
            {
               p34[0]=jie4;
            }
            p34[1]=_location[1];p34[2]=m2*p34[0]+n2;

            //画第一段直线
            const TopoDS_Edge& aedge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p1[0], p1[1], p1[2]), gp_Pnt(p2[0], p2[1], p2[2]));

            //画第一段圆弧
            Handle(Geom_TrimmedCurve) tc = GC_MakeArcOfCircle(gp_Pnt(p2[0], p2[1], p2[2]), gp_Pnt(p23[0], p23[1], p23[2]),
                    gp_Pnt(p3[0], p3[1], p3[2]));
            TopoDS_Edge makeArc = BRepBuilderAPI_MakeEdge(tc);

            //画第二段圆弧
            Handle(Geom_TrimmedCurve) tc2 = GC_MakeArcOfCircle(gp_Pnt(p3[0], p3[1], p3[2]), gp_Pnt(p34[0], p34[1], p34[2]),
                    gp_Pnt(p4[0], p4[1], p4[2]));
            TopoDS_Edge makeArc2 = BRepBuilderAPI_MakeEdge(tc2);

            //画第二段直线
            const TopoDS_Edge& aedge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4[0], p4[1], p4[2]), gp_Pnt(p5[0], p5[1], p5[2]));

            //画第三段直线
            const TopoDS_Edge& aedge4 = BRepBuilderAPI_MakeEdge(gp_Pnt(p5[0], p5[1], p5[2]), gp_Pnt(p6[0], p6[1], p6[2]));

            //画第四段直线
            const TopoDS_Edge& aedge5 = BRepBuilderAPI_MakeEdge(gp_Pnt(p6[0], p6[1], p6[2]), gp_Pnt(p7[0], p7[1], p7[2]));

            //画最后一段直线
            const TopoDS_Edge& aedge6 = BRepBuilderAPI_MakeEdge(gp_Pnt(p7[0], p7[1], p7[2]), gp_Pnt(p1[0], p1[1], p1[2]));

            //曲线连接组合的工具BRepBuilderAPI_MakeWire
            BRepBuilderAPI_MakeWire mkWire;
            //这里我们注意一定按照顺序去一个一个顺时针或者逆时针的去连接曲线，不然会形不了一个完整组合线
            mkWire.Add(aedge1);
            mkWire.Add(makeArc);
            mkWire.Add(makeArc2);
            mkWire.Add(aedge3);
            mkWire.Add(aedge4);
            mkWire.Add(aedge5);
            mkWire.Add(aedge6);

            TopoDS_Wire wireProfile = mkWire.Wire();  //由曲线连接在起来的一系列边的组合体

            //TopoDS_Face表示一个面的形状
            TopoDS_Face Face = BRepBuilderAPI_MakeFace(wireProfile);

            double angle = 360*PI / 180.00;//设置旋转的角度
            //创建轴线
            gp_Ax1 anAxis;
            anAxis.SetLocation(gp_Pnt(_location[0], _location[1], _location[2]));
            anAxis.SetDirection(gp_Dir(_direction[0], _direction[1], _direction[2]));

            //旋转形成三维几何体，BRepPrimAPI_MakeRevol为旋转形状工具
            TopoDS_Shape relvo= BRepPrimAPI_MakeRevol(Face,anAxis, angle, true);
            if (relvo.IsNull())
            {
                printLog(tr("Invalid parameters !"), 3);
                return false;
            }

            _occShapeAgent->updateShape(relvo);

        }
        catch (...)
        {
            printLog(tr("Invalid parameters !"), 3);
            return false;

        }
        return true;

    }

    FITKOCCModelLowDie::FITKOCCModelLowDie():OCCShapeAgent(this)
    {
        _shapeAgent=_occShapeAgent;
    }

    bool FITKOCCModelLowDie::update()
    {
        //异常处理
        try
        {
            double p1[3];
            p1[0]=_location[0];p1[1]=_location[1];p1[2]=_location[2];
            double p2[3];
            p2[0]=_location[0]+_length1+_length2+2*_radius;p2[1]=_location[1];p2[2]=_location[2];
            double p3[3];
            p3[0]=_location[0]+_length1+_length2+2*_radius;p3[1]=_location[1];p3[2]=_location[2]+_height0;
            double p4[3];
            p4[0]=_location[0]+_length1+2*_radius;p4[1]=_location[1];p4[2]=_location[2]+_height0;
            double p5[3];
            p5[0]=_location[0]+_length1+_radius;p5[1]=_location[1];p5[2]=_location[2]+_height0+_radius;
            double p6[3];
            p6[0]=_location[0]+_length1;p6[1]=_location[1];p6[2]=_location[2]+2*_radius+_height0;
            double p7[3];
            p7[0]=_location[0];p7[1]=_location[1];p7[2]=_location[2]+2*_radius+_height0;
            double o1[3];
            o1[0]=_location[0]+_length1+2*_radius;o1[1]=_location[1];o1[2]=_location[2]+_height0+_radius;
            double o2[3];
            o2[0]=_location[0]+_length1;o2[1]=_location[1];o2[2]=_location[2]+_height0+_radius;

            //先求解第一段圆弧中点坐标，在利用三点画圆弧（解直线和圆交点坐标）
            double y1 = o1[2] - (p4[2] + p5[2]) / 2;
            double x1 = o1[0] - (p4[0] + p5[0]) / 2;
            double m1 = y1 / x1;
            double n1 = -m1 * o1[0] + o1[2];
            double A1 = 1 + m1 * m1;
            double B1 = 2*m1*(n1-o1[2])-2*o1[0];
            double C1=o1[0]*o1[0]+(n1-o1[2])*(n1-o1[2])-_radius*_radius;
            double p45[3];
            double jie1 = (-B1 + sqrt(B1*B1-4*A1*C1))/(2*A1);
            double jie2 = (-B1 - sqrt(B1*B1-4*A1*C1))/(2*A1);
            if(jie1<=p4[0]&&jie1>=p5[0])
            {
                p45[0]=_location[0]+jie1;
            }
            else
            {
               p45[0]=_location[0]+jie2;
            }
            p45[1]=_location[1];p45[2]=_location[2]+m1*p45[0]+n1;

        //先求解第二段圆弧中点坐标，在利用三点画圆弧（解直线和圆交点坐标）
            double y2 = o2[2] - (p6[2] + p5[2]) / 2;
            double x2 = o2[0] - (p6[0] + p5[0]) / 2;
            double m2 = y2 / x2;//计算直线的斜率
            double n2 = -m2 * o2[0] + o2[2];//直线的截距
            double A2 = 1 + m2 * m2;
            double B2 = 2*m2*(n2-o2[2])-2*o2[0];
            double C2=o2[0]*o2[0]+(n2-o2[2])*(n2-o2[2])-_radius*_radius;
            double p56[3];
            double jie3 = (-B2 + sqrt(B2*B2-4*A2*C2))/(2*A2);
            double jie4 = (-B2 - sqrt(B2*B2-4*A2*C2))/(2*A2);
            if(jie3<=p5[0]&&jie3>=p6[0])
            {
                p56[0]=_location[0]+jie3;
            }
            else
            {
               p56[0]=_location[0]+jie4;
            }
            p56[1]=_location[1];p56[2]=_location[2]+m2*p56[0]+n2;

            //画第一段直线
            const TopoDS_Edge& aedge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p1[0], p1[1], p1[2]), gp_Pnt(p2[0], p2[1], p2[2]));

            //画第二段直线
            const TopoDS_Edge& aedge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p2[0], p2[1], p2[2]), gp_Pnt(p3[0], p3[1], p3[2]));

            //画第三段直线
            const TopoDS_Edge& aedge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(p3[0], p3[1], p3[2]), gp_Pnt(p4[0], p4[1], p4[2]));

            //画第一段圆弧
            Handle(Geom_TrimmedCurve) tc1 = GC_MakeArcOfCircle(gp_Pnt(p4[0], p4[1], p4[2]), gp_Pnt(p45[0], p45[1], p45[2]),
                    gp_Pnt(p5[0], p5[1], p5[2]));
            TopoDS_Edge makeArc1 = BRepBuilderAPI_MakeEdge(tc1);

            //画第三段直线
            //const TopoDS_Edge& aedge6 = BRepBuilderAPI_MakeEdge(gp_Pnt(p5[0], p5[1], p5[2]), gp_Pnt(p6[0], p6[1], p6[2]));

            //画第二段圆弧  生成圆弧的条件 ，用给定的三个点来定义一个圆弧。如果三个点不共线，会生成一个圆弧，共线的话将会失败
            Handle(Geom_TrimmedCurve) tc2 = GC_MakeArcOfCircle(gp_Pnt(p5[0], p5[1], p5[2]), gp_Pnt(p56[0],p56[1],p56[2]),
                    gp_Pnt(p6[0], p6[1], p6[2]));
            TopoDS_Edge makeArc2 = BRepBuilderAPI_MakeEdge(tc2);

            //画第四段直线
            const TopoDS_Edge& aedge4 = BRepBuilderAPI_MakeEdge(gp_Pnt(p6[0], p6[1], p6[2]), gp_Pnt(p7[0], p7[1], p7[2]));

            //画最后一段直线
            const TopoDS_Edge& aedge5 = BRepBuilderAPI_MakeEdge(gp_Pnt(p7[0], p7[1], p7[2]), gp_Pnt(p1[0], p1[1], p1[2]));

            //曲线连接组合的工具BRepBuilderAPI_MakeWire
            BRepBuilderAPI_MakeWire mkWire;
            //这里我们注意一定按照顺序去一个一个顺时针或者逆时针的去连接曲线，不然会形不了一个完整组合线
            mkWire.Add(aedge1);
            mkWire.Add(aedge2);
            mkWire.Add(aedge3);
            mkWire.Add(makeArc1);
            mkWire.Add(makeArc2);
            mkWire.Add(aedge4);
            mkWire.Add(aedge5);

            TopoDS_Wire wireProfile = mkWire.Wire();  //由曲线连接在起来的一系列边的组合体

            //TopoDS_Face表示一个面的形状
            TopoDS_Face Face = BRepBuilderAPI_MakeFace(wireProfile);

            double angle = 360*PI / 180.00;//设置旋转的角度
            //创建轴线
            gp_Ax1 anAxis;
            anAxis.SetLocation(gp_Pnt(_location[0], _location[1], _location[2]));
            anAxis.SetDirection(gp_Dir(_direction[0], _direction[1], _direction[2]));

            //旋转形成三维几何体，BRepPrimAPI_MakeRevol为旋转形状工具
            TopoDS_Shape relvo= BRepPrimAPI_MakeRevol(Face,anAxis, angle, true);
            if (relvo.IsNull())
            {
                printLog(tr("Invalid parameters !"), 3);
                return false;
            }

            _occShapeAgent->updateShape(relvo);

        }
        catch (...)
        {
            printLog(tr("Invalid parameters !"), 3);
            return false;

        }
        return true;

    }

    FITKOCCModelMidDie::FITKOCCModelMidDie():OCCShapeAgent(this)
    {
        _shapeAgent=_occShapeAgent;
    }

    bool FITKOCCModelMidDie::update()
    {

        // 异常处理。
        try
        {
            //创建轴线
            gp_Ax2 anAxis;
            anAxis.SetLocation(gp_Pnt(_location[0], _location[1], _location[2]));
            anAxis.SetDirection(gp_Dir(_direction[0], _direction[1], _direction[2]));
            //创建圆柱
            if (_length1 < 1e-9)
            {
                printLog(tr("Invalid length !"), 3);
                return false;
            }

            if (_radius < 1e-9)
            {
                printLog(tr("Invalid radius !"), 3);
                return false;
            }

            getAxis();
            gp_Circ Circle(anAxis, _radius);
            TopoDS_Shape aTopoCircle = BRepBuilderAPI_MakeEdge (Circle);
            const TopoDS_Edge &edge = TopoDS::Edge(aTopoCircle);
            TopoDS_Shape aPrism = BRepPrimAPI_MakePrism(edge, gp_Vec(_location[0], _location[1], _location[2]), true, false);
            if (aPrism.IsNull())
            {
                printLog(tr("Invalid parameters !"), 3);
                return false;
            }

            _occShapeAgent->updateShape(aPrism);

        }
        catch(...)
        {
            printLog(tr("Invalid parameters !"), 3);
            return false;
        }

        return true;
    }

    void FITKOCCModelMidDie::getAxis()
    {
        for (int i = 0; i < 3; ++i)
        {
            _location[i] = _direction[i];
        }

        double mod = sqrt(_location[0] * _location[0] + _location[1] * _location[1] + _location[2] * _location[2]);
        if (mod < 1e-6)
            return;

        double factor = _length1 / mod;
        for (int i = 0; i < 3; ++i)
            _location[i] *= factor;
    }


    FITKOCCModelSheet::FITKOCCModelSheet():OCCShapeAgent(this)
    {
        _shapeAgent=_occShapeAgent;
    }

    bool FITKOCCModelSheet::update()
    {
        //参考平面以坯饼的一半
        double THETA =acos((_radius1+_height*0.5)/(_radius1+_radius2));
        double L1 = sin(THETA)*_radius1;
        double L2 = sin(THETA)*_radius2;
        double H1 = _radius1-cos(THETA)*_radius1;
        double Inner =_radius0-_radius2-L1-L2;

        double p1[3];
        p1[0]=_location[0];p1[1]=_location[1];p1[2]=_location[2]+0.5*_height;
        double p2[3];
        p2[0]=_location[0]+Inner;p2[1]=_location[1];p2[2]=_location[2]+0.5*_height;
        double p3[3];
        p3[0]=_location[0]+Inner+L1;p3[1]=_location[1];p3[2]=_location[2]+0.5*_height+H1;
        double p4[3];
        p4[0]=_location[0]+_radius0;p4[1]=_location[1];p4[2]=_location[2];
        double p5[3];
        p5[0]=_location[0]+Inner+L1;p5[1]=_location[1];p5[2]=_location[2]-0.5*_height-H1;
        double p6[3];
        p6[0]=_location[0]+Inner;p6[1]=_location[1];p6[2]=_location[2]-0.5*_height;
        double p7[3];
        p7[0]=_location[0];p7[1]=_location[1];p7[2]=_location[2]-0.5*_height;
        double o1[3];
        o1[0]=_location[0]+Inner;o1[1]=_location[1];o1[2]=_location[2]+_radius1;
        double o2[3];
        o2[0]=_location[0]+_radius0-_radius2;o2[1]=_location[1];o2[2]=_location[2];
        double o3[3];
        o3[0]=_location[0]+Inner;o3[1]=_location[1];o3[2]=_location[2]-_radius1;

        //先求解第一段圆弧中点坐标，在利用三点画圆弧（解直线和圆交点坐标）
        double y1 = o1[2] - (p2[2] + p3[2]) / 2;
        double x1 = o1[0] - (p2[0] + p3[0]) / 2;
        double m1 = y1 / x1;
        double n1 = -m1 * o1[0] + o1[2];
        double A1 = 1 + m1 * m1;
        double B1 = 2*m1*(n1-o1[2])-2*o1[0];
        double C1=o1[0]*o1[0]+(n1-o1[2])*(n1-o1[2])-_radius1*_radius1;
        double p23[3];
        double jie1 = (-B1 + sqrt(B1*B1-4*A1*C1))/(2*A1);
        double jie2 = (-B1 - sqrt(B1*B1-4*A1*C1))/(2*A1);
        if(jie1<=p3[0]&&jie1>=p2[0])
        {
            p23[0]=_location[0]+jie1;
        }
        else
        {
           p23[0]=_location[0]+jie2;
        }
        p23[1]=_location[1];p23[2]=_location[2]+m1*p23[0]+n1+0.5*_height;

        //先求解第二段圆弧中点坐标，在利用三点画圆弧（解直线和圆交点坐标）
            double y2 = o3[2] - (p6[2] + p5[2]) / 2;
            double x2 = o3[0] - (p6[0] + p5[0]) / 2;
            double m2 = y2 / x2;
            double n2 = -m2 * o3[0] + o3[2];
            double A2 = 1 + m2 * m2;
            double B2 = 2*m2*(n2-o3[2])-2*o3[0];
            double C2=o3[0]*o3[0]+(n2-o3[2])*(n2-o3[2])-_radius1*_radius1;
            double p56[3];
            double jie3 = (-B2 + sqrt(B2*B2-4*A2*C2))/(2*A2);
            double jie4 = (-B2 - sqrt(B2*B2-4*A2*C2))/(2*A2);
            if(jie3<=p5[0]&&jie3>=p6[0])
            {
                p56[0]=_location[0]+jie3;
            }
            else
            {
               p56[0]=_location[0]+jie4;
            }
            p56[1]=_location[1];p56[2]=_location[2]+m2*p56[0]+n2-0.5*_height;


            //第一段直线
            const TopoDS_Edge& aedge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p1[0], p1[1], p1[2]), gp_Pnt(p2[0], p2[1], p2[2]));
            //第一段圆弧
            Handle(Geom_TrimmedCurve) tc1 = GC_MakeArcOfCircle(gp_Pnt(p2[0], p2[1], p2[2]), gp_Pnt(p23[0], p23[1], p23[2]), gp_Pnt(p3[0], p3[1], p3[2]));
            TopoDS_Edge makeArc1= BRepBuilderAPI_MakeEdge(tc1);
            //第二段圆弧
            Handle(Geom_TrimmedCurve) tc2 = GC_MakeArcOfCircle(gp_Pnt(p3[0], p3[1], p3[2]), gp_Pnt(p4[0], p4[1], p4[2]), gp_Pnt(p5[0], p5[1], p5[2]));
            TopoDS_Edge makeArc2= BRepBuilderAPI_MakeEdge(tc2);
            //第三段圆弧
            Handle(Geom_TrimmedCurve) tc3 = GC_MakeArcOfCircle(gp_Pnt(p5[0], p5[1], p5[2]), gp_Pnt(p56[0], p56[1], p56[2]), gp_Pnt(p6[0], p6[1], p6[2]));
            TopoDS_Edge makeArc3= BRepBuilderAPI_MakeEdge(tc3);
            //第二段直线
            const TopoDS_Edge& aedge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p6[0], p6[1], p6[2]), gp_Pnt(p7[0], p7[1], p7[2]));
            //第三段直线
            const TopoDS_Edge& aedge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(p7[0], p7[1], p7[2]), gp_Pnt(p1[0], p1[1], p1[2]));

            //曲线连接组合的工具BRepBuilderAPI_MakeWire
            BRepBuilderAPI_MakeWire mkWire;
            //这里注意一定按照顺序去一个一个顺时针或者逆时针的去连接曲线，不然会形不了一个完整组合线
            mkWire.Add(aedge1);
            mkWire.Add(makeArc1);
            mkWire.Add(makeArc2);
            mkWire.Add(makeArc3);
            mkWire.Add(aedge2);
            mkWire.Add(aedge3);

            TopoDS_Wire wireProfile = mkWire.Wire();  //由曲线连接在起来的一系列边的组合体

            //TopoDS_Face表示一个面的形状
            TopoDS_Face Face = BRepBuilderAPI_MakeFace(wireProfile);

            double angle = 360*PI / 180.00;//设置旋转的角度
            //创建轴线
            gp_Ax1 anAxis;
            anAxis.SetLocation(gp_Pnt(_location[0], _location[1], _location[2]));
            anAxis.SetDirection(gp_Dir(_direction[0], _direction[1], _direction[2]));

            //旋转形成三维几何体，BRepPrimAPI_MakeRevol为旋转形状工具
            TopoDS_Shape relvo= BRepPrimAPI_MakeRevol(Face,anAxis, angle, true);
            if (relvo.IsNull())
            {
                printLog(tr("Invalid parameters !"), 3);
                return false;
            }

            _occShapeAgent->updateShape(relvo);

        return true;

    }

    FITKOCCModelTwoCoins::FITKOCCModelTwoCoins():OCCShapeAgent(this)
    {
        _shapeAgent=_occShapeAgent;
    }

    bool FITKOCCModelTwoCoins::update()
    {

        QString name = this->getDataObjectName();
        TopoDS_Wire wireProfile;
        if(name.contains("Outer"))
        {
            //参考平面以坯饼的一半
            double THETA =acos((_radius1+_height*0.5)/(_radius1+_radius2));
            double L1 = sin(THETA)*_radius1;
            double L2 = sin(THETA)*_radius2;
            double H1 = _radius1-cos(THETA)*_radius1;
            double Inner =_radius0-_radius2-L1-L2;
            double start =_radius3+_length;
            double p1[3];
            p1[0]=_location[0]+start;p1[1]=_location[1];p1[2]=_location[2]+0.5*_height;
            double p2[3];
            p2[0]=_location[0]+Inner;p2[1]=_location[1];p2[2]=_location[2]+0.5*_height;
            double p3[3];
            p3[0]=_location[0]+Inner+L1;p3[1]=_location[1];p3[2]=_location[2]+0.5*_height+H1;
            double p4[3];
            p4[0]=_location[0]+_radius0;p4[1]=_location[1];p4[2]=_location[2];
            double p5[3];
            p5[0]=_location[0]+Inner+L1;p5[1]=_location[1];p5[2]=_location[2]-0.5*_height-H1;
            double p6[3];
            p6[0]=_location[0]+Inner;p6[1]=_location[1];p6[2]=_location[2]-0.5*_height;
            double p7[3];
            p7[0]=_location[0]+start;p7[1]=_location[1];p7[2]=_location[2]-0.5*_height;
            double o1[3];
            o1[0]=_location[0]+Inner;o1[1]=_location[1];o1[2]=_location[2]+_radius1;
            double o2[3];
            o2[0]=_location[0]+_radius0-_radius2;o2[1]=_location[1];o2[2]=_location[2];
            double o3[3];
            o3[0]=_location[0]+Inner;o3[1]=_location[1];o3[2]=_location[2]-_radius1;

            //先求解第一段圆弧中点坐标，在利用三点画圆弧（解直线和圆交点坐标）
            double y1 = o1[2] - (p2[2] + p3[2]) / 2;
            double x1 = o1[0] - (p2[0] + p3[0]) / 2;
            double m1 = y1 / x1;
            double n1 = -m1 * o1[0] + o1[2];
            double A1 = 1 + m1 * m1;
            double B1 = 2*m1*(n1-o1[2])-2*o1[0];
            double C1=o1[0]*o1[0]+(n1-o1[2])*(n1-o1[2])-_radius1*_radius1;
            double p23[3];
            double jie1 = (-B1 + sqrt(B1*B1-4*A1*C1))/(2*A1);
            double jie2 = (-B1 - sqrt(B1*B1-4*A1*C1))/(2*A1);
            if(jie1<=p3[0]&&jie1>=p2[0])
            {
                p23[0]=jie1;
            }
            else
            {
               p23[0]=jie2;
            }
            p23[1]=_location[1];p23[2]=_location[2]+m1*p23[0]+n1+0.5*_height;

            //先求解第二段圆弧中点坐标，在利用三点画圆弧（解直线和圆交点坐标）
                double y2 = o3[2] - (p6[2] + p5[2]) / 2;
                double x2 = o3[0] - (p6[0] + p5[0]) / 2;
                double m2 = y2 / x2;
                double n2 = -m2 * o3[0] + o3[2];
                double A2 = 1 + m2 * m2;
                double B2 = 2*m2*(n2-o3[2])-2*o3[0];
                double C2=o3[0]*o3[0]+(n2-o3[2])*(n2-o3[2])-_radius1*_radius1;
                double p56[3];
                double jie3 = (-B2 + sqrt(B2*B2-4*A2*C2))/(2*A2);
                double jie4 = (-B2 - sqrt(B2*B2-4*A2*C2))/(2*A2);
                if(jie3<=p5[0]&&jie3>=p6[0])
                {
                    p56[0]=jie3;
                }
                else
                {
                   p56[0]=jie4;
                }
                p56[1]=_location[1];p56[2]=_location[2]+m2*p56[0]+n2-0.5*_height;

                //第一段直线
                const TopoDS_Edge& aedge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p1[0], p1[1], p1[2]), gp_Pnt(p2[0], p2[1], p2[2]));
                //第一段圆弧
                Handle(Geom_TrimmedCurve) tc1 = GC_MakeArcOfCircle(gp_Pnt(p2[0], p2[1], p2[2]), gp_Pnt(p23[0], p23[1], p23[2]), gp_Pnt(p3[0], p3[1], p3[2]));
                TopoDS_Edge makeArc1= BRepBuilderAPI_MakeEdge(tc1);
                //第二段圆弧
                Handle(Geom_TrimmedCurve) tc2 = GC_MakeArcOfCircle(gp_Pnt(p3[0], p3[1], p3[2]), gp_Pnt(p4[0], p4[1], p4[2]), gp_Pnt(p5[0], p5[1], p5[2]));
                TopoDS_Edge makeArc2= BRepBuilderAPI_MakeEdge(tc2);
                //第三段圆弧
                Handle(Geom_TrimmedCurve) tc3 = GC_MakeArcOfCircle(gp_Pnt(p5[0], p5[1], p5[2]), gp_Pnt(p56[0], p56[1], p56[2]), gp_Pnt(p6[0], p6[1], p6[2]));
                TopoDS_Edge makeArc3= BRepBuilderAPI_MakeEdge(tc3);
                //第二段直线
                const TopoDS_Edge& aedge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p6[0], p6[1], p6[2]), gp_Pnt(p7[0], p7[1], p7[2]));
                //第三段直线
                const TopoDS_Edge& aedge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(p7[0], p7[1], p7[2]), gp_Pnt(p1[0], p1[1], p1[2]));

                //曲线连接组合的工具BRepBuilderAPI_MakeWire
                BRepBuilderAPI_MakeWire mkWire;
                //这里注意一定按照顺序去一个一个顺时针或者逆时针的去连接曲线，不然会形不了一个完整组合线
                mkWire.Add(aedge1);
                mkWire.Add(makeArc1);
                mkWire.Add(makeArc2);
                mkWire.Add(makeArc3);
                mkWire.Add(aedge2);
                mkWire.Add(aedge3);
                wireProfile = mkWire.Wire();

        }
        else if(name.contains("Inner"))
        {
            double p1[3];
            p1[0]=_location[0];p1[1]=_location[1];p1[2]=_location[2]+0.5*_height;
            double p2[3];
            p2[0]=_location[0]+_radius3;p2[1]=_location[1];p2[2]=_location[2]+0.5*_height;
            double p3[3];
            p3[0]=_location[0]+_radius3;p3[1]=_location[1];p3[2]=_location[2]-0.5*_height;
            double p4[3];
            p4[0]=_location[0];p4[1]=_location[1];p4[2]=_location[2]-0.5*_height;
            //第一段直线
            const TopoDS_Edge& aedge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p1[0], p1[1], p1[2]), gp_Pnt(p2[0], p2[1], p2[2]));
            //第二段直线
            const TopoDS_Edge& aedge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p2[0], p2[1], p2[2]), gp_Pnt(p3[0], p3[1], p3[2]));
            //第三段直线
            const TopoDS_Edge& aedge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(p3[0], p3[1], p3[2]), gp_Pnt(p4[0], p4[1], p4[2]));
            //第四段直线
            const TopoDS_Edge& aedge4 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4[0], p4[1], p4[2]), gp_Pnt(p1[0], p1[1], p1[2]));

            //曲线连接组合的工具BRepBuilderAPI_MakeWire
            BRepBuilderAPI_MakeWire mkWire;
            //这里注意一定按照顺序去一个一个顺时针或者逆时针的去连接曲线，不然会形不了一个完整组合
            mkWire.Add(aedge1);
            mkWire.Add(aedge2);
            mkWire.Add(aedge3);
            mkWire.Add(aedge4);

            wireProfile = mkWire.Wire();  //由曲线连接在起来的一系列边的组合体
        }

        //TopoDS_Face表示一个面的形状
        TopoDS_Face Face = BRepBuilderAPI_MakeFace(wireProfile);

        double angle = 360*PI / 180.00;//设置旋转的角度
        //创建轴线
        gp_Ax1 anAxis;
        anAxis.SetLocation(gp_Pnt(_location[0], _location[1], _location[2]));
        anAxis.SetDirection(gp_Dir(_direction[0], _direction[1], _direction[2]));

        //旋转形成三维几何体，BRepPrimAPI_MakeRevol为旋转形状工具
        TopoDS_Shape relvo= BRepPrimAPI_MakeRevol(Face,anAxis, angle, true);
        if (relvo.IsNull())
        {
            printLog(tr("Invalid parameters !"), 3);
            return false;
        }

        _occShapeAgent->updateShape(relvo);

        return true;

    }
}
